<template>
  <div v-show="showTable == 2" class="table-box">
    <div class="box-title">
      <p style="fontsize: 16px; fontweight: bold">
        {{ $t('intervalValueInformation') }}
      </p>
      <el-button
        :disabled="tableDisabled"
        type="success"
        icon="el-icon-plus"
        @click="pushSection"
      >{{ $t("add") }}</el-button
      >
    </div>
    <el-table
      :data="checkItemSections"
      :header-cell-style="headerCellStyle"
      border
      style="width: 100%"
      align="center"
      tooltip-effect="dark"
    >
      <el-table-column
        :label="$t('conditionNumber')"
        prop="conditions"
        width="160"
        align="center"
      >
        <template slot-scope="scope">
          <el-input
            v-model="scope.row.conditions"
            :disabled="tableDisabled"
            style="width: 130px"
          />
        </template>
      </el-table-column>
      <el-table-column :label="$t('Minimum')" prop="min" width="110" align="center">
        <template slot-scope="scope">
          <el-input
            v-model="scope.row.min"
            :disabled="tableDisabled"
            style="width: 80px"
          />
        </template>
      </el-table-column>
      <el-table-column
        :label="$t('containsTheEqualSign')"
        prop="containMin"
        width="150"
        align="center"
      >
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.containMin"
            :active-value="1"
            :inactive-value="0"
            :disabled="tableDisabled"
            style="display: block"
            active-color="#13ce66"
            inactive-color="#ff4949"
            active-text="YES"
            inactive-text="NO"
          />
        </template>
      </el-table-column>
      <el-table-column :label="$t('Max')" prop="max" width="110" align="center">
        <template slot-scope="scope">
          <el-input
            v-model="scope.row.max"
            :disabled="tableDisabled"

            style="width: 80px"
          />
        </template>
      </el-table-column>
      <el-table-column
        :disabled="tableDisabled"
        :label="$t('containsTheEqualSign')"
        prop="containMax"
        align="center"
        width="150"
      >
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.containMax"
            :active-value="1"
            :inactive-value="0"
            :disabled="tableDisabled"
            style="display: block"
            active-color="#13ce66"
            inactive-color="#ff4949"
            active-text="YES"
            inactive-text="NO"

          />
        </template>
      </el-table-column>
      <el-table-column :label="$t('isShow')" align="center">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.isShow"
            :active-value="1"
            :inactive-value="0"
            :disabled="tableDisabled"
            active-color="#13ce66"
            inactive-color="#ff4949"
          />
        </template>
      </el-table-column>
      <el-table-column :label="$t('action')" align="center">
        <template slot-scope="scope">
          <el-button
            :disabled="tableDisabled"
            type="text"
            @click="doSectionDelete(scope.$index, checkItemSections)"
          >{{ $t('delete') }}</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: 'SectionTable',
  components: {},
  mixins: [],
  props: {
    checkItemSections: {
      type: Array,
      default: () => { [] }
    },
    tableDisabled: {
      type: Boolean,
      default: false
    },
    showTable: {
      type: Number | String,
      default: 0 | ''
    }
  },
  data() {
    return {
      headerCellStyle: Object.freeze({
        background: '#F2F6FC',
        color: '#606266'
      })
    }
  },
  methods: {
    //   添加
    pushSection() {
      // 虽说不推荐直接修改props接收的值,但...还是成功了🤪🤪
      this.checkItemSections.push({})
    },
    //   删除
    doSectionDelete(index, rows) {
      rows.splice(index, 1)
    }
  }
}
</script>

<style scoped lang="scss">
.table-box {
  .box-title {
    height: 30px;
    box-sizing: border-box;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 20px 0;
  }
}
</style>
